<?php
//----------------------------------------------------------------------------//
// File               : 										  //
// Modification       :														  //
//----------------------------------------------------------------------------//
// Date(yyyy.mm.dd)   Developer                       Action				  //
//----------------------------------------------------------------------------//
//----------------------------------------------------------------------------//
// 2007.07.11         Dang Thanh                      Update				  //
//----------------------------------------------------------------------------//
?>
<?php
function V_CatSanphamAdd(&$arrayData,$mode)
{
	$mode=CM_getParameter("action");
	global $arrayError;
	
	$ulr = "?".MODUL."=catSanpham&".ACTION."=".$mode;//htmlspecialchars($_SERVER['QUERY_STRING']);
	$strButtonLabel =" Ghi lại ";
	$strLabel ="Sửa lại thông tin loại sản phẩm";
	if ($mode == "Add"){
		$strButtonLabel ="Thêm mới";	
		$strLabel ="Thêm mới thông tin loại sản phẩm";
	}	
	$strHienThi1 = 'checked="checked"';
	$strHienThi0 = '';
	if($arrayData["hien_thi"]==0 && $mode!="Add"){
		$strHienThi1 = '';
		$strHienThi0 = 'checked="checked"';
	}
	//	htmlentities(
	?>
	<script language=javascript>
	function doUpload() {
		if (document.f.ten_loai_sp.value=="") {
			alert("Tên loại sản phẩm không được rỗng");
			document.f.ten_loai_sp.focus();
			return false;
		}
		if (document.f.thu_tu.value=="") {
			alert("thứ tự hiển thị không được rỗng");
			document.f.thu_tu.focus();
			return false;
		}		
		if (isNaN(document.f.thu_tu.value)) {
			alert("Thứ tự sắp xếp phải là kiểu số");
			document.f.thu_tu.value="";
			document.f.thu_tu.focus();
			return false;
		}	
		
		var filename = document.f.userfile.value;
		var dotpos;
		filename = filename.substring(filename.lastIndexOf("\\")+1,filename.length);
		dotpos=filename.lastIndexOf('.');
		ext=filename.substr(dotpos+1,3);
		ext=ext.toLowerCase();
		fname=filename.substr(0,dotpos);
		if (document.f.userfile.value!="") {
			if(dotpos==-1||dotpos==0){
				alert("Xin lỗi bạn click vào browser để chọn đúng đường dẫn.");
				return false;
			}
		}
	
		if (ext!="")
			if ((ext!="gif") && (ext!="jpg") && (ext!="png")  && (ext!="bmp")){
				alert("We only accept file format of GIF, JPG, PNG. Please try again.");
				return false;
			}


		return true;
	}
	

function showImage(urlimage)
{
	
	if(document.f.userfile.value!=""){
		choseImage(document.f.userfile.value);
		
	}else{
		choseImage(urlimage);
	}
}


function btnClearImgOnclick(){
	if (document.f.userfile.value != ""){
		if (confirm("Bạn có muốn xóa ảnh không?")){
			document.f.previewField.src = "";
			//document.f.chu_thich_anh.value = "";
			document.getElementById("fn").value='';
			document.getElementById("fileIDSpan").innerHTML=
					"<input name=\"userfile\" type=\"file\" id=\"fn\"  size=\"100\" value=\"\" onChange=\" showImage();\"/>";
		}
	}
}
function Focus(){
document.f.ten_loai_sp.focus();
}
</script>
<?= CM_showError() ?>
<style type="text/css">
<!--
.style2 {color: #000066}
-->
</style>
<body onLoad="Focus();">
<table width="100%">
  <tr><td>
 <form enctype="multipart/form-data" action="<?=$ulr;?>" method="post" name="f" id="f" onSubmit="return doUpload();">
	<input type="hidden" name="id" value="<?=htmlspecialchars($arrayData["id"])?>" />
	<input type="hidden" name="parent_id" value="<?=htmlspecialchars($arrayData["parent_id"])?>" />
	<input type="hidden" name="curPg" value="<?=CM_getParameter("curPg");?>" /> 
<TABLE width="100%" border="1" cellpadding="3" cellspacing="0" bordercolor="#FF9900" bordercolordark="white">
    <TBODY>
      <TR align="center" bgcolor="#FFE59F">
        <TD width="100%" height="17" align="center" valign="middle" id=th1><strong><?=$strLabel?></strong></TD>
      </TR>
    </TBODY>
  </table>
  <TABLE width="100%" border="1" cellpadding="3" cellspacing="0" bordercolor="#FF9900" bordercolordark="white">
     <TBODY>
      <TR>
        <TD width="20%" height="22" bgcolor="#FFE59F"  class=bk12-140><span  style="font-family:Arial; font-size:14px; color:#000066; ">Tên loại sản phẩm:<span style="color:#FF0000;">*</span></span></TD>
        <TD width="80%" align="left"  class=bk12-140>
          <input name="ten_loai_sp" type="text" id="ten_loai_sp" value="<?=htmlspecialchars($arrayData["ten_loai_sp"])?>" style="width:400px; " maxlength="22" />
        </TD>
      </TR>
      <tr>
      	<TD width="20%" height="22" bgcolor="#FFE59F"  class=bk12-140><span  style="font-family:Arial; font-size:14px; color:#000066; ">Icon loại sản phẩm:<span style="color:#FF0000;">*</span></span></TD>
        <TD width="80%" align="left"  class=bk12-140>
           <!-- <input name="icon_loai_sp" type="text" id="icon_loai_sp" value="<?=htmlspecialchars($arrayData["icon_loai_sp"])?>" style="width:400px; " maxlength="22" /> -->
        	<?
		  	if($mode=="Edit" && $arrayData["icon_loai_sp"] != ''){
			  ?>
			 <font size="2" face="Verdana, Arial, Helvetica, sans-serif"> <?=htmlspecialchars($arrayData["icon_loai_sp"])?>
			 </font><br>
			 <?
				}else{}
			 ?>
		 	 <span id="fileIDSpan">
            <input name="userfile" type="file" id="fn"  size="50" value="<?=htmlspecialchars($arrayData["icon_loai_sp"])?>" onChange="showImage();"/>
           </span></font>	
		</TD>
      </tr>
	  <TR>
	  	<TD width="20%" height="22" bgcolor="#FFE59F"  class=bk12-140>
			<span  style="font-family:Arial; font-size:14px; color:#000066; ">Loại sản phẩm bậc 1:</span>
		</TD>
		<TD>
			<select name="parent_id_add" style="WIDTH: 200px">
				 <option value="0">Null</option>
				<?
					global $db;
					include_once(DIR_MODEL."md_cat_san_pham.class.php");
					$objcatSanpham = new MD_CatSanpham($db);
					$arrayDataCat =  array();  
					$arrayDataCat = $objcatSanpham->getByWhere("id,ten_loai_sp,parent_id","parent_id=0","");
					$parent_id0 = CM_getParameter("parent_id");
									
					//$cat_id = $arrayData["cat_id"];
					if (!empty($arrayDataCat)) { 
						foreach  ($arrayDataCat as $row)
							{
								if($row['id']==$parent_id0  ){
									$selected0 = "selected";
								}else{
									$selected0 = "";
								}
								$id = $row['id'];
								$name=$row["ten_loai_sp"];
								
								echo"<option value=$id ".$selected0.">$name</option>";
								
							}
							unset($arrayDataCat);
					}else{
						echo "<option value=0>Null</option>";
					}
				
				?>
			</select>
		</TD>
	  </TR>
	   <TR>
        <TD width="20%" height="22" bgcolor="#FFE59F"  class=bk12-140><span  style="font-family:Arial; font-size:14px; color:#000066; ">Mô tả:</span></TD>
        <TD width="80%" align="left"  class=bk12-140>
         <textarea name="thuoc_tinh_sp" cols="50" rows="5" id="thuoc_tinh_sp" style="width:400px; "><?=htmlspecialchars($arrayData["thuoc_tinh_sp"])?></textarea>
        </TD>
      </TR>
	  <TR>
        <TD height="22" bgcolor="#FFE59F" class=bk12-140><span class="style2">Thứ tự hiển thị:</span><span style="color:#FF0000;">*</span></TD>
        <TD  class=bk12-140>
          <input name="thu_tu" type="text" align="right" id="thu_tu" value="<?=htmlspecialchars($arrayData["thu_tu"])?>" size="4" maxlength="4" />
        </TD>
      </TR>
      <TR>
        <TD height="22" bgcolor="#FFE59F"  class=bk12-140><span style="font-family:Arial; font-size:14px; color:#000066;">Hiển th&#7883;:</span></TD>
        <TD align="left"  class=bk12-140>
          <input name="hien_thi" type="radio" value="1" <?=$strHienThi1?> / checked="checked">
		  <font size="2" face="Verdana, Arial, Helvetica, sans-serif">
			C&oacute;</label>
          <input name="hien_thi" type="radio" value="0" <?=$strHienThi0 ?> />
          <label> Kh&ocirc;ng</label>
        </TD>
      </TR>
     
    </TBODY>
	
  </TABLE>
  <TABLE width="100%" border="1" cellpadding="3" cellspacing="0" bordercolor="#FF9900" bordercolordark="white">
    <TBODY>
      <TR align="center" >
        <TD width="100%" height="17" align="center" valign="middle" id=th1><strong><span class="bk12-140"><strong>
          <input name="Reset" type="reset" value="Nhập lại" />
        </strong></span><span class="bk12-140"><strong>
        <input name="Submit" type="submit" value="<?=$strButtonLabel?>" />
        <strong>
        <input type="button" name="back" value="Tr&#7903; l&#7841;i" onClick="history.go(-1)">
        </strong> </strong></span></strong></TD>
      </TR>
</TBODY>
</table>
</form>
</td></tr></table>
</body>
	  <?php
	}
?>

